package com.briup.ptp.web.controller;


import com.briup.ptp.entity.House;
import com.briup.ptp.utils.Result;

import com.briup.ptp.service.HouseService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/columnHouse")
@Api(tags = "栏舍管理")
@CrossOrigin
public class HouseController {

    @Autowired
    private HouseService service;


    @GetMapping("/query")
    @ApiOperation("分页+条件查询栏舍信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "name", value = "栏舍名", readOnly = true),
                    @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true)
            }
    )

    public Result queryHouseInfo(String name, Integer pageNum, Integer pageSize) {
        PageInfo<House> houses =  service.queryHouseInfo(name,pageNum, pageSize);
        return Result.success(houses);

    }

    @PostMapping ("/saveOrUpdate")
    @ApiOperation("新增+修改栏舍信息")
    public Result saveOrUpdateHouse(@RequestBody House house) {

        service.saveOrUpdateHouse(house);
        return Result.success();
    }

    @ApiOperation("删除栏舍信息")
    @DeleteMapping("/deleteById/{Id}")
    public Result deleteHouse(@PathVariable Integer id){
        service.deleteHouse(id);
        return Result.success();

    }
    @ApiOperation("批量删除栏舍信息")
    @DeleteMapping("/deleteByIdAll")
    public Result  batchDeleteHosue(@RequestBody List<Integer> id){
        service.batchDeleteHouse(id);
        return Result.success();

    }

}
